<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/common/head.jsp"%>
</head>
<body class="${cookie.bodyClass.value}">
	<div class="container body">
		<div class="main_container">
			<%@ include file="/WEB-INF/common/left.jsp"%>
			<%@ include file="/WEB-INF/common/top.jsp"%>
			<!-- page content -->
			<div class="right_col" role="main" id="main">
				<div class="x_panel">
					<div class="x_title">
						<h2>会员管理列表
						<small>总待返利积分:<font color="red">${totalMemberWaitRebatePoints}</font></small>
						<small>总已返利积分:<font color="red">${totalMemberAlreadyRebatePoints}</font></small>
						<small>今日总返利金积分:<font color="red">${totalTodayRebateGoldPoints}</font></small>
						<small>今日总返利银积分:<font color="red">${totalTodayRebateSilverPoints}</font></small>
						</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<form role="form" id="searchForm">
							<div class="container">
								<div class="row">
									<div class="col-lg-3">
										<input class="form-control input-sm" placeholder="昵称" name="map['nickName']"/>
									</div>
									<div class="col-lg-3">
										<input class="form-control input-sm" placeholder="手机号" name="map['cellphone']"/>
									</div>
									<div class="col-lg-3">
										<select class="form-control input-sm" name="map['sex']">
											<option value="">--性别--</option>
											<option value="0">保密</option>
											<option value="1">男</option>
											<option value="2">女</option>
										</select>
									</div>
								</div>
								<div class="row">
									<div class="col-lg-3">
										<select class="form-control input-sm" name="map['status']">
											<option value="">--状态--</option>
											<option value="0">正常</option>
											<option value="1">禁用</option>
										</select>
									</div>
									<div class="col-lg-1">
										<button type="button" class="btn btn-primary btn-sm" onclick="search();">搜索</button>
									</div>
									<div class="col-lg-6">
										
									</div>
								</div>
							</div>
						</form>
						<div class="table-responsive">
							<table id="banners" class="table table-bordered table-striped table-hover" 
							  cellspacing="0" width="100%">
								<thead>
									<tr class="mytableHead">
										<th class="myRowNumber"></th>
									<!-- 	<th>id</th> -->
										<th>用户头像</th>
										<th>用户昵称</th>
										<th>手机号</th>
										<th>状态</th>
										<th>是否认证</th>
										<th>性别</th>
										<th>注册时间</th>
										<th>操作</th>
									</tr>
								</thead>
							</table>
						</div>
					</div>
				</div>
			</div>
			<!-- /page content -->
			<%@ include file="/WEB-INF/common/foot.jsp"%>
		</div>
	</div>
	<%@ include file="/WEB-INF/common/script.jsp"%>
	<script>
	$(function(){
		var t = $("#banners").DataTable({
		    ajax: {
		        url: ctx+'admin/member/findMembers',
		        type: 'POST',
		        data: function(d){$.extend(d,serializeObject($("#searchForm")))}
		    },
		    columns: [
		        { "data":null,"render":rowNumberRender},
		       /*  { "data":'id'}, */
		        { "data":'headImg',"render":imageUrlRender},
		        { "data":'nickName'},
		        { "data":'cellphone'},
		        { "data":'status',"render":statusRender},
		        { "data":'isIdentification',"render":indentRender},
		        { "data":'sex',"render":sexRender},
		        { "data":'registerDate',"render":rowisCreatedTime},
		        { "data":'id',"render":optRender}
		    ]
		    
		});
		$("#searchForm input").keydown(function(event){
			if(event.keyCode == 13){
				search();
			}
		});
		$("#searchForm select").change(search);
	});
	
	function optRender(data, type, row, meta){
	    var but = '<a class="btn btn-info btn-xs" href="javascript:view('+meta.row+')"><i class="fa fa-pencil"></i>查看</a>';
	    var status = row.status;
	    if(Number(status)==0){
        	but = but + '<a class="btn btn-info btn-xs" href="javascript:disable('+meta.row+')"><i class="fa fa-pencil"></i>禁用</a>';
        }
        if(Number(status)==1){
            but = but + '<a class="btn btn-info btn-xs" href="javascript:enable('+meta.row+')"><i class="fa fa-pencil"></i>启用</a>';
        }
        but = but + '<a class="btn btn-info btn-xs" href="javascript:pointsRebate('+meta.row+')"><i class="fa fa-pencil"></i>查看返利明细</a>';
		return but;
	}
	function view(index,event){
		var row = $('#banners').DataTable().rows().data()[index];
		window.location = ctx+"admin/member/toMemberDetailPage?memberId="+row.id;
	}
	function pointsRebate(index,event){
		var row = $('#banners').DataTable().rows().data()[index];
		window.location = ctx+"admin/pointsRebate/toPointsRebatePage?memberId="+row.id;
	}
	
	function rowNumberRender(data, type, row, meta) {
	    var setting = meta.settings;
	    var rowNumber = setting._iDisplayStart + (meta.row + 1);
		return rowNumber;
  	}
	
	function imageUrlRender(data, type, row, meta){
		var imageUrl=row.headImg;
		return "<img style='width:100px;height:50px' src='"+imgDomain+"/"+imageUrl+"'/>";
	}
	function statusRender(data, type, row, meta){
		var place=row.status;//状态(0正常1禁用)
		if (place=="0") {
			return "正常";
		}
		if (place=="1") {
			return "禁用";
		}
	}
    function indentRender(data, type, row, meta){
        var place=row.isIdentification;//是否认证（0否，1是）
        if (place=="0") {
            return "否";
        }
        if (place=="1") {
            return "是";
        }
    }
    function sexRender(data, type, row, meta){
        var place=row.sex;//轮播子类型 0私教、1课程、2商品
        if (place=="0") {
            return "保密";
        }
        if (place=="1") {
            return "男";
        }
        if (place=="2") {
            return "女";
        }
    }
	function search(){
		$('#banners').DataTable().ajax.reload(function(d){$.extend(d,serializeObject($("#searchForm")))}, true);
	}
    function disable(index,event) {
        var row = $('#banners').DataTable().rows().data()[index];
        var memberId = row.id;
        swal({
            "title" : "",
            "text" : "正在处理……请稍后",
            "showConfirmButton" : false
        });
        $.ajax({
            url : ctx + "admin/member/disableMember",
            dataType : "json",
            data : {"memberId":memberId},
            success : function(result) {
                if (result.status == "0") {
                    swal({
                        title : '',
                        text : "操作成功"
                    }, function() {
                        back();
                    });
                } else {
                    swal({
                        title : '',
                        text : result.msg,
                        type : "error"
                    });
                }
            }
        });
    }
    function enable(index,event) {
        var row = $('#banners').DataTable().rows().data()[index];
        var memberId = row.id;
        swal({
            "title" : "",
            "text" : "正在处理……请稍后",
            "showConfirmButton" : false
        });
        $.ajax({
            url : ctx + "admin/member/enableMember",
            dataType : "json",
            data : {"memberId":memberId},
            success : function(result) {
                if (result.status == "0") {
                    swal({
                        title : '',
                        text : "操作成功"
                    }, function() {
                        back();
                    });
                } else {
                    swal({
                        title : '',
                        text : result.msg,
                        type : "error"
                    });
                }
            }
        });
    }
    function rowisCreatedTime(data, type, row, meta){
        var registerDate = row.registerDate;
        if(Number(registerDate)>0){
            return new Date(parseInt(registerDate)).format("yyyy-MM-dd hh:mm:ss");
        }else{
            return '';
        }
    }
    function back() {
        window.location = ctx + "admin/member/toMemberPage";
    }
    Date.prototype.format = function(format)
    {
        var o = {
            "M+" : this.getMonth()+1, //month
            "d+" : this.getDate(),    //day
            "h+" : this.getHours(),   //hour
            "m+" : this.getMinutes(), //minute
            "s+" : this.getSeconds(), //second
            "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
            "S" : this.getMilliseconds() //millisecond
        }
        if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
            (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)if(new RegExp("("+ k +")").test(format))
            format = format.replace(RegExp.$1,
                RegExp.$1.length==1 ? o[k] :
                    ("00"+ o[k]).substr((""+ o[k]).length));
        return format;
    }

	</script>
</body>
</html>